using B.S.NewMedical.Api.Read.Application.Command.Doctor;
using B.S.NewMedical.Api.Read.DTOS.Doctor;
using B.S.NewMedical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace B.S.NewMedical.Api.Read.Controllers.Doctor
{
    [Route("api/[controller]")]
    [ApiController]
    public class PrescriptionController : ControllerBase
    {
        private readonly IMediator _mediator;

        public PrescriptionController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取开单申请列表
        /// </summary>
        /// <param name="userId">用户ID，可选</param>
        /// <param name="status">状态，可选</param>
        /// <param name="pageIndex">当前页码，默认1</param>
        /// <param name="pageSize">每页大小，默认10</param>
        /// <param name="includeDetails">是否包含明细，默认false</param>
        /// <returns>开单申请列表</returns>
        [HttpGet("GetPrescriptionApplications")]
        public async Task<ApiResult<List<PrescriptionApplicationDto>>> GetPrescriptionApplications(
            [FromQuery] int? userId = null,
            [FromQuery] int? status = null,
            [FromQuery] int pageIndex = 1,
            [FromQuery] int pageSize = 10,
            [FromQuery] bool includeDetails = false)
        {
            return await _mediator.Send(new GetPrescriptionApplicationsCommand(userId, status, pageIndex, pageSize, includeDetails));
        }

        /// <summary>
        /// 获取开单申请详情
        /// </summary>
        /// <param name="applicationId">开单申请ID</param>
        /// <returns>开单申请详情</returns>
        [HttpGet("GetPrescriptionApplicationDetail/{applicationId}")]
        public async Task<ApiResult<PrescriptionApplicationDetailDto>> GetPrescriptionApplicationDetail(int applicationId)
        {
            return await _mediator.Send(new GetPrescriptionApplicationDetailCommand(applicationId));
        }
    }
} 